<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>打断字符串为指定数量的字串</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.wordwrap" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">wordwrap</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.2, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">wordwrap</span> &mdash; <span class="dc-title">打断字符串为指定数量的字串</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.wordwrap-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>wordwrap</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$width</code><span class="initializer"> = 75</span></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$break</code><span class="initializer"> = &quot;\n&quot;</span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$cut</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
  ]]] ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   使用字符串断点将字符串打断为指定数量的字串。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.wordwrap-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">str</code></dt>

     <dd>

      <p class="para">
       输入字符串。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">width</code></dt>

     <dd>

      <p class="para">
       列宽度。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">break</code></dt>

     <dd>

      <p class="para">
       使用可选的 <code class="parameter">break</code> 参数打断字符串。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">cut</code></dt>

     <dd>

      <p class="para">
       如果 <code class="parameter">cut</code> 设置为 <strong><code>TRUE</code></strong>，字符串总是在指定的 <code class="parameter">width</code> 或者之前位置被打断。因此，如果有的单词宽度超过了给定的宽度，它将被分隔开来。（参见第二个范例）。
       当它是  <strong><code>FALSE</code></strong> ，函数不会分割单词，哪怕 <code class="parameter">width</code> 小于单词宽度。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.wordwrap-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回打断后的字符串。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.wordwrap-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-6008">
    <p><strong>Example #1 <span class="function"><strong>wordwrap()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"The&nbsp;quick&nbsp;brown&nbsp;fox&nbsp;jumped&nbsp;over&nbsp;the&nbsp;lazy&nbsp;dog."</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$newtext&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">wordwrap</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">20</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$newtext</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
The quick brown fox&lt;br /&gt;
jumped over the lazy&lt;br /&gt;
dog.
</pre></div>
    </div>
   </div>
   <div class="example" id="example-6009">
    <p><strong>Example #2 <span class="function"><strong>wordwrap()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"A&nbsp;very&nbsp;long&nbsp;woooooooooooord."</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$newtext&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">wordwrap</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">8</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$newtext</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
A very
long
wooooooo
ooooord.
</pre></div>
    </div>
   </div>
   
   <div class="example" id="example-6010">
    <p><strong>Example #3 <span class="function"><strong>wordwrap()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"A&nbsp;very&nbsp;long&nbsp;woooooooooooooooooord.&nbsp;and&nbsp;something"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$newtext&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">wordwrap</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">8</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$newtext</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
A very
long
woooooooooooooooooord.
and
something
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.wordwrap-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="nl2br.html" class="function" rel="rdfs-seeAlso">nl2br()</a> - 在字符串所有新行之前插入 HTML 换行标记</span></li>
    <li class="member"><span class="function"><a href="chunk_split.html" class="function" rel="rdfs-seeAlso">chunk_split()</a> - 将字符串分割成小块</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>